package com.yuexun.dhdoctor.module.departmentDocumentNew.presenter.impl;



import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.departmentDocumentNew.bean.DocDepartBean;
import com.yuexun.dhdoctor.module.departmentDocumentNew.model.IUserDepartDocTreeModel;
import com.yuexun.dhdoctor.module.departmentDocumentNew.presenter.IUserDepartDocTreePresenter;
import com.yuexun.dhdoctor.module.departmentDocumentNew.view.IUserDepartDocTreeView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wangt on 2017/7/14.
 */

public class UserDepartDocTreePresenter implements IUserDepartDocTreePresenter {
    private IUserDepartDocTreeView view;
    private IUserDepartDocTreeModel model;

    public UserDepartDocTreePresenter(IUserDepartDocTreeView view, IUserDepartDocTreeModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void getDepartTree(Map<String, String> praise) {
        model.getDepartTree(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<DocDepartBean>>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast(e.toString());
                    }

                    @Override
                    public void onNext(BaseEntity<DocDepartBean> docDepartBean) {
                        view.showDepartTree(docDepartBean);
                    }
                });
    }
}
